home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 31
/
Aminet 31 (1999)(Schatztruhe)[!][Jun 1999].iso
/
Aminet
/
dev
/
c
/
DependantScan.lha
/
DependantScan
/
Source
/
ArgumentsDpS.c
next >
Wrap
C/C++ Source or Header
|
1999-02-20
|
22KB
|
355 lines
#define DEF_ARGUMENTSDPS_C
#include <exec/types.h>
#include <workbench/startup.h>
#include <proto/icon.h>
#include <clib/dos_protos.h>
#include <clib/exec_protos.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "DependantScan.h"
#include "ProcessDirectory.h"
#include "RequesterError.h"
#include "LocaleSupport.h"
/*
void parse_scoptions_for_argument(
char *scoptions_variable, the string to look for in the scoptions file
int argument_number, the argument to assign it to
char *line_buffer) static buffer (of size PD_PATHMAX) to store lines and variable value
* Description
This function will attempt to build the name of the scoptions file and get the specified SAS/C variable's value from that file. If
successful, the DPSArgument[argument_number] variable will be set to the value fetched from the scoptions file.
*/
void parse_scoptions_for_argument(
char *scoptions_variable, /* the string to look for in the scoptions file */
int argument_number, /* the argument to assign it to */
char *line_buffer) /* static buffer (of size PD_PATHMAX) to store lines and variable value */
{
FILE *stream; /* will be connected to the file specified by 'scoptions_name' */
char scoptions_name[PD_PATHMAX]; /* name of scoptions file */
size_t variable_length = strlen(scoptions_variable); /* remember how long the scoptions variable is */
if (DPSArgument[DPS_ARG_PATH] == NULL) /* if the current directory is to be used */
strcpy(scoptions_name,DPS_SCOPTIONS_FILENAME); /* then, no path information for the scoptions file should be used */
else /* either not the shell or the WB */
dps_build_path(scoptions_name,DPS_SCOPTIONS_FILENAME); /* build the name of the scoptions file */
if ((stream = fopen(scoptions_name,"r")) != NULL) /* if we can open the file */
{
while (fgets(line_buffer,PD_PATHMAX,stream)) /* while we can get a line from the file */
{
if (!memcmp(line_buffer,scoptions_variable,variable_length)) /* if this line mentions the variable we are looking for */
{
DPSArgument[argument_number] = line_buffer + variable_length; /* get the variable's value */
if (strchr(line_buffer,'\n')) /* if the line contains a new-line */
*strchr(line_buffer,'\n') = '\0'; /* remove the new-line */
break; /* we are done */
}
}
fclose(stream); /* clean up after ourselves */
}
}
/*
void parse_scoptions_for_project(void)
* Description
This function will attempt to parse the value of DPSArgument[DPS_ARG_PROJECT] from the scoptions file. If successful, the
DPSArgument[DPS_ARG_PROJECT] variable will be set to the value fetched from the scoptions file.
*/
void parse_scoptions_for_project(void)
{
static char line_buffer[PD_PATHMAX]; /* required by parse_scoptions_for_argument() */
parse_scoptions_for_argument(DPS_PROGRAMNAME_STRING,DPS_ARG_PROJECT,line_buffer); /* actually do the parsing */
}
/*
void parse_scoptions_for_object_dir(void)
* Description
This function will attempt to parse the value of DPSArgument[DPS_ARG_OBJECT_DIR] from the scoptions file. If successful, the
DPSArgument[DPS_ARG_OBJECT_DIR] variable will be set to the value fetched from the scoptions file.
*/
void parse_scoptions_for_object_dir(void)
{
static char line_buffer[PD_PATHMAX]; /* required by parse_scoptions_for_argument() */
parse_scoptions_for_argument(DPS_OBJECTNAME_STRING,DPS_ARG_OBJECT_DIR,line_buffer); /* actually do the parsing */
}
/*
BOOL dps_get_shell_arguments(
struct RDArgs *rdargs) where to place the on-line help
* Description
This function gets the command-line arguments when the program is spawned from the shell.
* Return Value
TRUE = successful, a call to FreeArgs() is necessary
FALSE = unsuccessful, a call to FreeArgs() is not necessary
*/
BOOL dps_get_shell_arguments(
struct RDArgs *rdargs) /* where to place the on-line help */
{
BOOL free_args_needed = FALSE; /* value that is returned, TRUE is good, FALSE is bad */
char *project; /* tells if the user specified a project name */
char *object_dir; /* for determining if the user specified an object directory */
static long files_on_line = DPS_DEFAULT_FILESONLINE; /* the default number of files per line */
int index; /* for accessing our messages */
char arg_lower_name[40]; /* lower case version of a command line option */
char *arg_type; /* the type of the current argument */
char *arg_name; /* for pointing to various parts of the the current argument */
char *next_text; /* where the next bit of text should go */
int longest_arg_name = 0; /* the length of the longest argument name */
char *template = NULL; /* the template as supplied to DOS */
if ((rdargs->RDA_ExtHelp = AllocVec(2048,0)) == NULL) /* if we cannot get some memory for our help text */
{quick_requester_error(DPS_ERROR_CANNOT_ALLOCATE,DPS_ERROR_CANNOT_ALLOCATE,2048); goto _ABORT;}
if ((template = AllocVec(DPS_LINE_BUFFER_SIZE,0)) == NULL) /* if we cannot get some memory for the DOS template */
{quick_requester_error(DPS_ERROR_CANNOT_ALLOCATE,DPS_ERROR_CANNOT_ALLOCATE,DPS_LINE_BUFFER_SIZE); goto _ABORT;}
strcpy(rdargs->RDA_ExtHelp,locale_support_string(DPSCatalog, DPS_MSG_USAGE)); /* intialize the help text */
next_text = rdargs->RDA_ExtHelp + strlen(rdargs->RDA_ExtHelp); /* setup where to start appending information */
for (index = 0; index < DPS_ARG_COUNT; ++index) /* access all of the command line options */
{
arg_type = locale_support_string(DPSCatalog, DPS_ARG_COUNT+1+index); /* get the type of argument we are dealing with */
arg_name = locale_support_string(DPSCatalog, index); /* get the name of the argument */
if (strlen(arg_name) > longest_arg_name) /* if this argument is even longer than the others */
longest_arg_name = strlen(arg_name); /* remember which one is the longest */
if (strstr(arg_type,"/K")) /* if this is a key word */
{
strcpy(arg_lower_name,arg_name); /* get a working copy of the argument name */
strlwr(arg_lower_name); /* convert the copy to lower case */
next_text += sprintf(next_text," [%s %s]",arg_name,arg_lower_name);
}
else if (strstr(arg_type,"/S")) /* if this is a switch type argument */
{
next_text += sprintf(next_text," [%s]",arg_name);
}
else /* NOTE: handle other cases as needed */
{
next_text += sprintf(next_text,"%s",arg_name);
}
if (index == (DPS_ARG_COUNT/2)) /* if we are at the half way mark */
/* put a break in the arguments */
next_text += sprin